<template>
  <nav>
    <span class="city" @click="goToCity">{{ cityName }}</span>
    <ul>
      <router-link
        v-for="item in navList"
        :key="item.title"
        tag="li"
        :to="'/home/movies' + item.url"
      >
        {{ item.title }}
      </router-link>
    </ul>
    <span class="iconfont icon-search"></span>
  </nav>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      // activeTitle: sessionStorage.getItem("title") || "热映",
      navList: [
        {
          title: "热映",
          url: "/hot",
        },
        {
          title: "影院",
          url: "/cinema",
        },
        {
          title: "待映",
          url: "/wait",
        },
        {
          title: "经典电影",
          url: "/classic",
        },
      ],
    };
  },
  // computed: {
  //   cityName() {
  //     return this.$store.state.cityName;
  //   },
  // },
  // computed: mapState(["cityName"]),
  computed: mapState({
    cityName: (state) => state.city.cityName,
  }),
  methods: {
    goToCity() {
      this.$router.push("/city");
    },
    // handleClick(item) {
    //   this.activeTitle = item.title;
    //   //todo 本地存储的内容是不会被刷新的
    //   sessionStorage.setItem("title", this.activeTitle);
    //   this.$router.push("/home/movies" + item.url);
    // },
  },
  // watch: {
  //   $route(to) {
  //     console.log(to);
  //   },
  // },
};
</script>

<style lang="less" scoped>
@import "../../../../assets/css/var.less";
nav {
  width: 100%;
  height: 44px;
  background: #fff;
  border-bottom: 1px solid @border-color;
  display: flex;
  font-size: @m-font;

  .city {
    width: 62px;
    .center();
  }

  ul {
    flex: 1;
    display: flex;
    padding: 0 20px;
    font-size: @s-font;
    font-weight: 900;

    li {
      flex: 2;
      .center();

      &:last-child {
        flex: 3;
      }
    }

    .router-link-active {
      font-size: @m-font;
      position: relative;

      &::after {
        content: "";
        position: absolute;
        width: 20px;
        height: 3px;
        background: @theme-color;
        bottom: 4px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 1.5px;
      }
    }
  }

  .icon-search {
    width: 45px;
    .center();
    color: @theme-color;
    font-weight: 900;
  }
}
</style>
